#include <iostream>
#include <sstream>
#include <string> 
#include <vector>
#include <queue>
#include <stack>
#include <list>

using namespace std;

class ResourceList{
    public:
     explicit ResourceList(int start, int cap){
        for(int i=0; i<cap;i++){
            inner_list_.emplace_back(start+i);
            index_map_.emplace(start+i,)
        }
     }

    void dyn(int size){
        for(int i=0; i<size;i++){
            inner_list_.pop_front();
        }
    }


    void spc(int id){
        auto it = inner_list_.begin();
        for(;it !=inner_list_.end(); ++it){
            if(*it==id){
                break;
            }
        }
        if(it != inner_list_.end()){
            inner_list_.erase(it);
        }
    }

    void release(int id){
        inner_list_.emplace_back(id);
    }
    int first(){
        return inner_list_.front();
    }

private:
std::list<int> inner_list_{};
unordered_map <int,std::list<int>::iterator. index_map_{};


};



int main(){
    int begin,end;
    cin>>begin>>end;
    ResourceList list(begin,end-begin+1);
    int n;
    cin>>n;
    for(int i=0; i< n; ++i){
        int op,num;
        cin>>op;
        if(op==1){
            cin>>num;
            list.dyn(num);
        }
        else if(op==2){
            cin>>num;
            list.spc(num);
        }
        else if(op==3){
            cin>>num;
            list.release(num);
        }
    } 
    cout<< list.first()<<endl;
    return 0;
}